<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">会员列表</p>
        </div>
        <div class="view-container">
            <el-form :model="queryParams" ref="queryForm" :inline="true">
                <el-form-item label="手机号" prop="phone">
                    <el-input
                        v-model="queryParams.phone"
                        placeholder="会员手机号检索"
                        size="small"
                        maxlength="11"
                        @keyup.enter.native="handleQuery"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
                </el-form-item>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button
                        class="btn-success"
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="add()"
                        v-hasPermi="['system:memberInformation:insert']"
                    >新建</el-button>
                </el-col>
            </el-row>
            <el-table v-loading="loading" :data="list" @row-click="handleView" border>
                <el-table-column label="序号" type="index" align="center" width="50">
                    <template slot-scope="scope">
                        <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="手机号"  align="center" prop="phone" />
                <el-table-column label="姓名" align="center" prop="name" />
                <el-table-column label="性别" align="center" prop="sex" />
                <!-- <el-table-column label="生日" align="center" prop="dateOfBirth" /> -->
                <!-- <el-table-column label="学历" align="center" prop="education" /> -->
                <el-table-column label="备注" align="center" prop="remarks" />
                <!-- <el-table-column label="最近一次登录" align="center" prop="lastLoginTime" /> -->
                <el-table-column label="状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <div v-if="scope.row.status == '0'" style="color:#13C2C2">草稿</div>
                        <div v-if="scope.row.status == '1'" style="color:#13C2C2">待审核</div>
                        <div v-if="scope.row.status == '2'" style="color:#52C41A">已审核</div>
                        <div v-if="scope.row.status == '3'" style="color:#fd562c">拒绝</div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-delete"
                            @click.native.stop="handleDelete(scope.row)"
                            v-hasPermi="['system:memberInformation:remove']"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </div>
    </div>
</template>

<script>
import { memberSendDataList, memberDelete } from "@/api/system/member/member"
export default {
    name: "list",
    data() {
        return {
            // 遮罩层
            loading: true,
            // 总条数
            total: 0,
            // 列表数据
            list: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                phone: '', // 手机号
            },
            type: '',
            id: '',
            data: ''
        }
    },
    created() {
        if(this.$route.query.type){
            this.type = this.$route.query.type
            this.id = this.$route.query.id
            this.data = this.$route.query.data
        }
        this.getList()
    },
    methods: {
        // 获取列表
        getList() {
            this.loading = true
            memberSendDataList(this.addDateRange(this.queryParams)).then(res => {
                this.list = res.rows
                this.total = res.total
                this.loading = false
            })
        },
        // 搜索按钮
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        // 重置按钮
        resetQuery() {
            this.resetForm("queryForm")
            this.handleQuery()
        },
        // 新建
        add(){
            this.$router.push({path:"/customer/member/add"})
        },
        // 查看
        handleView(row) {
            if(this.type == 'salesOrderAdd'){
                if(row.status == '2'){
                    if(this.id){
                        this.$tab.closeOpenPage({path:"/sales/salesOrder/add",query:{ member: row, data: this.data, id: this.id }})
                    }else{
                        this.$tab.closeOpenPage({path:"/sales/salesOrder/add",query:{ member: row, data: this.data }})
                    }
                }else{
                    this.$modal.msgError('请选择已审核的会员！')
                }
            }else if(this.type == 'salesOrderEdit'){
                if(row.status == '2'){
                    this.$tab.closeOpenPage({path:"/sales/salesOrder/edit",query:{ member: row, data: this.data, id: this.id }})
                }else{
                    this.$modal.msgError('请选择已审核的会员！')
                }
            }else{
                this.$router.push({path:"/customer/member/detail",query:{id: row.memberInformationId}})
            }
        },
        // 删除
        handleDelete(row){
            this.$modal.confirm('是否确认删除？').then(() => {
                memberDelete(row.memberInformationId).then(() => {
                    this.getList()
                    this.$modal.msgSuccess("删除成功")
                })
            }).catch(() => {})
        },
    }
}
</script>